package com.jiadakeji.ppm.modules.weixin.entity;


import com.jiadakeji.ppm.common.utils.IdGen;
import com.jiadakeji.ppm.common.utils.WechatUtils;
import com.jiadakeji.ppm.modules.business.entity.FeeReceive;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * 微信统一下单请求对象
 *
 * @Author xuelongjiang
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "xml")//xml的根元素
public class WechatUnifiedorderRequest  implements Serializable{


    private String appid;//服务商ID 是 可用map
    private String mch_id;//商户号 是
    private String sub_appid;//小程序的app ID 是 //注意：在扫码方式下，此参数可以不填

    public String getProduct_id() {
        return product_id;
    }

    public void setProduct_id(String product_id) {
        this.product_id = product_id;
    }

    private String sub_mch_id;//子商户号 是
    private String device_info;//设备号 否
    private String nonce_str;//随机字符串 是
    private String sign;//签名 是
    private String sign_type;//签名类型 否  微信默认为 MD5
    private String body;//商品描述 是
    private String detail;//商品详情  否
    private String attach;//附加数据 否
    private String out_trade_no;//商户订单号 是
    private String fee_type;//货币类型 否  微信默认为 人民币
    private String total_fee;//总金额 是
    private String spbill_create_ip;//终端ID 是
    private String time_start;//交易起始时间 否
    private String time_expire;//交易结束时间 否
    private String goods_tag;//商品标记 否
    private String notify_url;//通知地址 是
    private String trade_type;//交易类型 是
    private String limit_pay;//指定支付方式 否
    private String openid;//用户标识  二选一
    private String sub_openid;//用户子标识 否



    //扫码参数
    private String product_id;// 商品id




    //TODO 小程序初始化
    public WechatUnifiedorderRequest() {

        this.appid = WechatUtils.appid;//小程序appid  佳达
        this.mch_id = WechatUtils.mch_id;//服务商商号
        this.sub_appid = WechatUtils.sub_appid;//子商户的appId
        this.sub_mch_id = WechatUtils.sub_mch_id;
        this.notify_url = WechatUtils.feeReceiveNotifyUrl;//支付回调url TODO 使用配置文件
        this.trade_type = "JSAPI";//小程序交易类型
        this.nonce_str = IdGen.uuid();//32位随机字符串
        this.body = "桂林洋物业缴费";

    }



    /*//TODO 扫码支付 初始化
    public WechatUnifiedorderRequest(String nativePay){
        if("nativePay".equals(nativePay)){

            this.appid = "wxf5fbd2f1a39c4b31";//公众号appid  朗特塞
            this.mch_id = "1491068992";//服务商商号
            //this.sub_appid = "wxbc2b85a153bb23c4";//小程序的appId
            this.notify_url = "https://marketking.jiadakeji.cn/api/v1/onorder/wechatNotify";//支付回调url TODO 使用配置文件
            this.trade_type = "NATIVE";//扫码支付
            this.nonce_str = IdGen.uuid();//32位随机字符串
            this.body = "海南朗特赛数据科技有限公司";
        }
    }*/


    /**
     *
     * @param openid
     * @param feeReceive
     * @param ip
     */
    public void setUnifiedorder(String openid, FeeReceive feeReceive, String ip){

        this.out_trade_no = feeReceive.getCode();
        Double totalPriceDouble = feeReceive.getPayAmount()*1000/10;
        String totalPrice =   String.valueOf  ((Integer)totalPriceDouble.intValue());
        this.total_fee = totalPrice;
        this.spbill_create_ip = ip;
        this.sub_openid = openid;

    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getSub_appid() {
        return sub_appid;
    }

    public void setSub_appid(String sub_appid) {
        this.sub_appid = sub_appid;
    }

    public String getSub_mch_id() {
        return sub_mch_id;
    }

    public void setSub_mch_id(String sub_mch_id) {
        this.sub_mch_id = sub_mch_id;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getSign_type() {
        return sign_type;
    }

    public void setSign_type(String sign_type) {
        this.sign_type = sign_type;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getFee_type() {
        return fee_type;
    }

    public void setFee_type(String fee_type) {
        this.fee_type = fee_type;
    }

    public String getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(String total_fee) {
        this.total_fee = total_fee;
    }

    public String getSpbill_create_ip() {
        return spbill_create_ip;
    }

    public void setSpbill_create_ip(String spbill_create_ip) {
        this.spbill_create_ip = spbill_create_ip;
    }

    public String getTime_start() {
        return time_start;
    }

    public void setTime_start(String time_start) {
        this.time_start = time_start;
    }

    public String getTime_expire() {
        return time_expire;
    }

    public void setTime_expire(String time_expire) {
        this.time_expire = time_expire;
    }

    public String getGoods_tag() {
        return goods_tag;
    }

    public void setGoods_tag(String goods_tag) {
        this.goods_tag = goods_tag;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public String getTrade_type() {
        return trade_type;
    }

    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }

    public String getLimit_pay() {
        return limit_pay;
    }

    public void setLimit_pay(String limit_pay) {
        this.limit_pay = limit_pay;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getSub_openid() {
        return sub_openid;
    }

    public void setSub_openid(String sub_openid) {
        this.sub_openid = sub_openid;
    }
}
